/**
 * 
 */
package fr.fermeManager.application.views.utils;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;

import org.apache.commons.lang.StringUtils;

import fr.fermeManager.library.model.beans.TypeTransaction;

/**
 * @author Mo
 * 
 */
public class RenderComboBoxTypeTransaction extends DefaultListCellRenderer {

	public RenderComboBoxTypeTransaction() {
		super();
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax
	 * .swing.JList, java.lang.Object, int, boolean, boolean)
	 */
	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

		if (value instanceof TypeTransaction) {
			TypeTransaction typeTransacTmp = ((TypeTransaction) value);
			if (typeTransacTmp.getIdParent() == null) {
				setFocusable(false);
				setEnabled(false);
				setVisible(false);
				setText(null);
			} else {
				setText(StringUtils.repeat(" -", (typeTransacTmp.getLevel() - 1) * 2) + " " + typeTransacTmp.getLibelle());
				if (typeTransacTmp.getIdParent() == 0) {
					setFont(getFont().deriveFont(Font.BOLD));
				}
			}
			setFont(getFont().deriveFont(Font.BOLD));
			if (typeTransacTmp.isEstSortie()) {
				setForeground(Color.decode("#8B0000"));
			}
		}
		return this;
	}

}
